/**
 * 考試管理初始化
 */
var IncompleteTest = {
    id: "IncompleteTestTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
IncompleteTest.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', hidden: true},
        {title: '考试名称：', field: 'theTestName', align: 'center', valign: 'middle',},
        {
            title: '考试时间：',
            field: 'timeLength',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value+"分钟";
            }
        },
        {
            title: '创建时间：', field: 'createTime', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                return value.substring(0, 10);
            }
        },
        {title: '试卷总分：', field: 'totalScore', align: 'center', valign: 'middle',},
        {title: '通过分数：', field: 'scoresOfAdoption', align: 'center', valign: 'middle',},
        {title: '创建人：', field: 'createPeople', align: 'center', valign: 'middle'},
        {title: '备注：', field: 'remark', align: 'center', valign: 'middle'},
        {
            title: '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ',
            field: '', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                return '<a onclick="IncompleteTest.inIncompleteTest(\'' + row.id + '\');" href="javascript:;" >进入考试</a>';
            }
        }
    ];
};
IncompleteTest.inIncompleteTest = function (id) {
    var ajax = new $ax(Feng.ctxPath + "/incompleteTest/rein/"+ id, function (data) {
        window.location.href =  Feng.ctxPath +"/testing";
        alert('进入考试!');
    }, function (data) {
        Feng.error("内部故障!" + data.responseJSON.message + "!");
    });
    ajax.start();
};
 
/**
 * 打开查看贷款产品详情
 */
IncompleteTest.update_test_list = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '考试详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/incompleteTest/incompleteTest_update/' + IncompleteTest.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 检查是否选中
 */
IncompleteTest.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        IncompleteTest.seItem = selected[0];
        return true;
    }
};

IncompleteTest.getMoney = function (url) {
    window.location.href = url;
}


IncompleteTest.resetSearch = function () {
    IncompleteTest.search();
};

IncompleteTest.formParams = function () {
    var queryData = {};
    return queryData;
}

var parseParam = function (param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function (i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

/**
 * 查询考試列表
 */
IncompleteTest.search = function () {
    IncompleteTest.table.refresh({query: IncompleteTest.formParams()});
};

$(function () {
    var defaultColunms = IncompleteTest.initColumn();
    var table = new BSTable(IncompleteTest.id, "/incompleteTest/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(IncompleteTest.formParams());
    IncompleteTest.table = table.init();
    brs.innerHTML="</br></br></br></br>";
    br5s.innerHTML="</br></br></br></br></br>"
});
